$(document).ready(function(){
    $('.change-status button').live('click',function(){
        var category_id = $(this).attr('category_id');
        var $this = $(this);
        $.ajax({
			url: admin_url + 'category/change_status',
			type:'post',
			data:{category_id:category_id},
			success:function(data){
				obj = JSON.parse(data);
                var _this = $this;
                _this.html(obj.html);
                _this.attr('status', obj.status);
                if(obj.status == "1")
                {
                    _this.removeClass('red');
                    _this.removeClass('green');
                    _this.addClass('green');
                }
                if(obj.status == "0")
                {
                    _this.removeClass('red');
                    _this.removeClass('green');
                    _this.addClass('red');
                }

			}
		});	
    });
    
    $('.delete_category').click(function(){
        var category_id = $(this).attr('category_id');
        var array_attr = {delete_category:"delete_category", category_id:category_id}; 
        open_modal_confirm('Xác nhận', 'Bạn có chắc chắn muốn xóa...', array_attr);
    });
    
    $('#modal_confirm button[delete_category=delete_category]').live('click',function(){
        var category_id = $(this).attr('category_id');
        $.ajax({
			url: admin_url + 'category/delete_category',
			type:'post',
			data:{category_id:category_id},
			success:function(data){
				location.reload();
			}
		});
    });
    
});


